﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;


namespace aaaaa
{
    public class SkySphere
    {
        CModel model;
        Effect effect;
        Skymodel skyModel;

        /// <summary>
        /// Cria um cubo que recebrá a projeção da textura fornecida
        /// </summary>
        /// <param name="Content"></param>
        /// <param name="GraphicsDevice"></param>
        /// <param name="Texture"></param>
        public SkySphere(ContentManager Content, GraphicsDevice GraphicsDevice, 
            TextureCube Texture)
        {
            
            model = new CModel(Content.Load<Model>("sky/skysphere_mesh"), Vector3.Zero,
                Vector3.Zero, Vector3.One, GraphicsDevice);

            effect = Content.Load<Effect>("sky/skysphere_effect");
            effect.Parameters["CubeMap"].SetValue(Texture);

            model.SetModelEffect(effect, false);

            //this.graphics = GraphicsDevice;
        }
        /// <summary>
        /// Contructor for SkySphere using fx, dds and FBX they must all be in the same folder
        /// </summary>
        /// <param name="Content">Games Content used to call the fx and FBX</param>
        /// <param name="GraphicsDevice">Used for CModel contructor \n (Will be removed)</param>
        /// <param name="strTexture">String of file name for sky to be used
        /// \n (NOTE: must go into class to change the location of other 2 files if not in default directory)</param>
        public SkySphere(ContentManager Content, GraphicsDevice GraphicsDevice,
           string strTexture)
        {

            model = new CModel(Content.Load<Model>("skysphere_mesh"), Vector3.Zero,
                Vector3.Zero, Vector3.One, GraphicsDevice);
            /* TODO:
             *  Fazer refactor na classe GameOmbejct3D para aceitar efeitos  genericos alem do
             *  BasicEffect
             */
            skyModel = new Skymodel(Content.Load<Model>("skysphere_mesh"));

            TextureCube Texture = Content.Load<TextureCube>(strTexture);

            effect = Content.Load<Effect>("skysphere_effect");
            effect.Parameters["CubeMap"].SetValue(Texture);

            model.SetModelEffect(effect, false);

            //this.graphics = GraphicsDevice;
        }

        /// <summary>
        /// Desenha um mapa de textura cubico que será projetado no cubo criado pela classe
        /// </summary>
        /// <param name="BasicCamera">Camera para seguir</param>
        /// <param name="GraphicsDevice">Usado para definior o depth buffer</param>
        public void Draw(BasicCamera camera, GraphicsDevice GraphicsDevice)
        {
            // Disable the depth buffer
            GraphicsDevice.DepthStencilState = DepthStencilState.None;

            // Move the model with the sphere
            model.Position = camera.Position;

            model.Draw(camera.ViewMatrix, camera.ProjectionMatrix, camera.Position);

            GraphicsDevice.DepthStencilState = DepthStencilState.Default;
        }
    }

    class Skymodel : GameObject3D
    {


        public Skymodel(Model model)
            : base(model)
        {
            
        }
        public override void Update(GameTime gameTime)
        {
        }
    }

}
